package huaweiod.second;

import java.util.Scanner;

/**
 * 高效货运
 * https://renjie.blog.csdn.net/article/details/135009940
 */
public class C12_EfficientDelivery {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int wa = in.nextInt();
        int wb = in.nextInt();
        int wt = in.nextInt();
        int pa = in.nextInt();
        int pb = in.nextInt();

        wt = wt - wa - wb;
        System.out.println(process(0, wa, pa, wb, pb, wt, pa + pb));
    }

    public static int process(int index, int wa, int pa, int wb, int pb, int rest, int price) {
        if (index == 2) {
            return price;
        }
        // 选a
        int ans = price;
        if (index == 0) {
            for (int i = 0; wa * i <= rest; i++) {
                ans = Math.max(ans, process(index + 1, wa, pa, wb, pb, rest - wa * i, price + pa * i));
            }
        }
        // 选b
        if (index == 1) {
            for (int i = 0; wb * i <= rest; i++) {
                ans = Math.max(ans, process(index + 1, wa, pa, wb, pb, rest - wb * i, price + pb * i));
            }
        }
        return ans;
    }
}
